//
//  EmploymentDetTwoCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/27.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "EmploymentDetTwoCell.h"
#import "KILabel.h"
@interface EmploymentDetTwoCell ()

@property (weak, nonatomic) IBOutlet UILabel *topLabel;
@property (weak, nonatomic) IBOutlet UILabel *middleLabel;
@property (weak, nonatomic) IBOutlet KILabel *bottomLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UITextView *textViewField;

@end


@implementation EmploymentDetTwoCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.bottomMargin.constant = 10;
    
    self.lineView.backgroundColor = lineGray;
    
    self.topLabel.font = MYFONT(16);
    
    self.middleLabel.font = MYFONT(15);
    
    self.bottomLabel.text = nil;
    
//    self.bottomLabel.font = MYFONT(14);
  
    self.middleLabel.textColor = darkGray;
    
//    self.textViewField.delegate = self;
    
    UIView *keybordView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenW, 2)];
    
    keybordView.backgroundColor = [UIColor clearColor];
    
    self.textViewField.inputView = keybordView;
    
    self.textViewField.tintColor = [UIColor clearColor];
    
    myViewModel.textView = self.textViewField;
    
}


//- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//    return NO;
//}


- (void)setModel:(EmploymentListModel *)model{
    _model = model;
    
//    _model.position_desc = @"工作作风踏实，能吃苦耐劳，学习精神强，良好的团队协作精神工作作风踏实，能吃苦耐劳，学习精神强，良好的团队协作精神工作作风踏实，能吃苦耐劳，学习精神强，良好的团队协作精神工作作风踏实，能吃苦耐劳，学习精神强，良好的团队协作精神514674526@qq.com";
    

    
    self.bottomLabel.attributedText = [self attributedString:_model.position_desc withFont:MYFONT(14)];
    
    self.bottomLabel.hidden = YES;
    
     self.textViewField.attributedText = [self attributedString:_model.position_desc withFont:MYFONT(14)];
//    [self.textViewField becomeFirstResponder];
    
//    KILinkTapHandler tapHandler = ^(KILabel *label, NSString *string, NSRange range) {
//        
//        [self tappedLink:string];
//    };
//    
//    self.bottomLabel.userHandleLinkTapHandler = tapHandler;
//    self.bottomLabel.urlLinkTapHandler = tapHandler;
//    self.bottomLabel.hashtagLinkTapHandler = tapHandler;
}

- (void)dealloc{
    
    
    NSLog(@"textviewdfsdfdsfd");
}



- (void)tappedLink:(NSString *)link
{
    
//    NSString *title = [NSString stringWithFormat:@"Tapped %@", link];
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:link
                                                                   message:nil
                                                            preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"复制" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [UIPasteboard generalPasteboard].string = link;
        
        
    }]];
    
    
    [self.viewController presentViewController:alert animated:YES completion:nil];
}



- (NSAttributedString *)attributedString:(NSString *)str withFont:(UIFont *)font{
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:str];
    
    [attr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, str.length)];
    
    [attr addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, str.length)];
    
    [attr addAttribute:NSKernAttributeName value:@(1.0f) range:NSMakeRange(0, str.length)];
    
    NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc]init];
    
    para.lineSpacing = 1;
    
    [attr addAttribute:NSParagraphStyleAttributeName value:para range:NSMakeRange(0, str.length)];
    
    return attr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    
}

@end
